package com.tinycomment.dbutils;

import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class OracleHelper extends SqlHelper {
    String dbUrl = "jdbc:oracle:thin:@bej301461.cn.oracle.com:1521:tdd";
    String dbUser = "tdduser";
    String dbPw = "Welcome1";

    public OracleHelper() {
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            connection = DriverManager.getConnection(this.dbUrl, this.dbUser, this.dbPw);

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
/*
    @Override
    public boolean ExecuteSql(String sql) {
        int result = 0;
        Statement stmt = null;
        try {
            stmt = connection.createStatement();
            result = stmt.executeUpdate(sql);
            stmt.close();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            this.close();
        }
        return result > 0;
    }

    @Override
    public boolean ExecuteSql(String sql, Parameter[] paraArray) {
        int result = 0;
        PreparedStatement stmt = null;
        try {
            stmt = this.connection.prepareStatement(sql);
            this.DealParameter(stmt, paraArray);
            result = stmt.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            this.close();
        }
        return result > 0;
    }

    @Override
    public ResultSet getResultSet(String sql) {
        String strQuery = sql;

        ResultSet rs = null;
        try {
            Statement stmtQuery = connection.createStatement();
            rs = stmtQuery.executeQuery(strQuery);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return rs;
    }

    @Override
    public ResultSet getResultSet(String sql, Parameter[] paraArray) {
        ResultSet rs = null;
        try {
            PreparedStatement stmt = this.connection.prepareStatement(sql);
            this.DealParameter(stmt, paraArray);
            rs = stmt.executeQuery();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return rs;
    }*/
}
